package models

import (
	"time"
)

type User struct {
	ID         uint      `gorm:"type:int;primaryKey;autoIncrement comment:'id'" json:"id"`
	CreatedAt  time.Time `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt  time.Time `gorm:"autoUpdateTime" json:"updated_at"`
	UserID     int       `gorm:"type:bigint(20);not null;unique;column:user_id;uniqueIndex:'idx_userid'" json:"user_id"`
	UserName   string    `gorm:"type:varchar(100);not null;unique;column:username;index:'idx_username'"  json:"username" binding:"required"`
	PassWord   string    `gorm:"type:varchar(100);not null;column:password" json:"password" binding:"required"`
	Email      *string   `gorm:"type:varchar(60)" validate:"omitempty,email;column:email" json:"email" binding:"email"`
	Gender     int8      `gorm:"type:tinyint(4);default:0;column:gender; comment:'0是男,1是女'" json:"gender"`
	RePassword string    `gorm:"-" json:"repassword" binding:"required,eqfield=PassWord"`

	// 新增：用户与文章的一对多关系
	Articles []Article `gorm:"foreignKey:AuthorID;references:UserID" json:"-"`
}
type LoginReq struct {
	Username string `json:"username" binding:"omitempty,max=20"`
	UserID   int    `json:"user_id"`
	Password string `json:"password" binding:"required,max=20,min=6"`
	Email    string `json:"email" binding:"omitempty,email"`
}

func (u *User) TableName() string {
	return "user"
}
